package com.example.springbootquartz.job;

import com.example.springbootquartz.bean.User;
import com.example.springbootquartz.mapper.UserMapper;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.util.Calendar;
import java.util.Date;

/**
 * @version 0.1
 * @auth admin.
 * @time 2018/5/27 16:36
 * @since 0.1
 */
public class MyJob extends QuartzJobBean {

    @Autowired
    private UserMapper userMapper;

    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        User user = userMapper.queryUserLimitFirst();
        Calendar calendar = Calendar.getInstance();
        user.setModifyTime(calendar.getTime());
        userMapper.updateUserById(user);

        System.out.println(context.getTrigger().getKey().getName()+"  "+user.toString());
    }
}
